<template>
	<view class="container">
		<view class="inputEdit">
			<input v-model="formData.relevancePhone" placeholder="输入账号" placeholder-style="font-size:28rpx;" />
		</view>
		<view class="inputEdit">
			<input v-model="formData.relevancePassword" placeholder="输入密码" placeholder-style="font-size:28rpx;" />
		</view>
		<view  class="button" @click="addFn">登录</view>
	</view>
</template>

<script setup>
	import { computed ,ref,reactive,toRefs,onMounted} from 'vue';
	import { onLoad,onShow, onPageScroll, onPullDownRefresh } from '@dcloudio/uni-app';
	import sheep from '@/sheep';

  
  const formData=ref({
	  userId:'',
	  relevancePhone:'',//关联的手机号
	  relevancePassword:'',//关联密码
	  curAvatar:'',//当前人的头像
	  curPhone:'',//当前人的手机号
	  curPassword:'',//当前人的密码
  })
  onLoad(()=>{
	  console.log(sheep.$store('user').userInfo);
	  formData.value.userId=sheep.$store('user').userInfo.id
	  formData.value.curAvatar=sheep.$store('user').userInfo.avatar
	  formData.value.curPhone=sheep.$store('user').userInfo.phone
	  formData.value.curPassword=sheep.$store('user').userInfo.password
  })

const addFn=()=>{
	console.log(formData.value);
	if(!formData.value.relevancePassword && !formData.value.relevancePhone){
		uni.showToast({
			title:'填写完整',
			icon:'none',
		})
		return false
	}
	
	sheep.$api.login.addAccount(formData.value).then(res=>{
		console.log(res);
		if(res.code==200){
			uni.showToast({
				title:'提交成功'
			})
			sheep.$store('user').logout()
			sheep.$store('user').login({ phone:formData.value.relevancePhone,  password:formData.value.relevancePassword})
			
			// uni.navigateBack({delta:1})
		}else{
			uni.showToast({
				title:res.msg,
				icon:'none'
			})
		}
	})
}


</script>

<style lang='scss' scoped>
	page{
		padding-top:100rpx;
	}
	.container{
		margin:80rpx;
	}
	
	.inputEdit{
		background-color: #fff;
		padding: 30rpx 50rpx;
		margin-bottom: 40rpx;
	}
	.button{
		text-align: center;
		background-image: linear-gradient(90deg,#f7a7ba,#f8bfce,#f8d0d9);
		color: #fff;
		padding:20rpx;
		border-radius: 10rpx;
	}
</style>